package com.cfg.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cfg.domain.CfgCategory;
import com.cfg.domain.CfgCategoryVo;
import com.cfg.mapper.CfgCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CfgCategoryService extends ServiceImpl<CfgCategoryMapper, CfgCategory> {

    @Autowired
    CfgCategoryMapper cfgCategoryMapper;

//    public List<TreeSelect> getCategory(CfgCategory getCategory) {
//
//    }

    /**
     * 根据配置名称获取配置id
     * @param type
     * @return
     */
    public String getCategoryIdByType(String type){
        try{
            QueryWrapper<CfgCategory> wrapper = Wrappers.query();
            wrapper.eq("BIZNAME",type);
            List<CfgCategory> list = cfgCategoryMapper.selectList(wrapper);
            if(list!=null && list.size()>0){
                return list.get(0).getId();
            }else{
                return "";
            }
        }catch (Exception exception){
            return exception.getMessage();
        }
    }
}
